<template>
  <div>
    <a-date-picker :defaultValue="defaultValue" 
      :showTime="option.withTime" 
      :format="format" 
      @change="handleChange"></a-date-picker>
  </div>
</template>

<script>
import moment from 'moment'
export default {
  name: 'Date',
  props: {
    option: {
      type: Object,
      required: false,
      default: () => {
        return {
          withTime: false,
          defaultDate: undefined,
          defaultDateTime: undefined
        };
      }
    },
    defaultHelp: {
      type: String,
      required: false,
      default: () => {
        return '';
      }
    }
  },
  computed: {
    defaultValue() {
      if (this.option.withTime) {
        if (this.option.defaultDateTime) {
          return moment(this.option.defaultDateTime);
        }
      } else if (this.option.defaultDate) {
        return moment(this.option.defaultDate);
      }
    },
    format() {
      return this.option.withTime ? 'YYYY-MM-DD HH:mm:ss' : 'YYYY-MM-DD';
    }
  },
  methods: {
    handleChange(date, dateStr) {
      this.$emit('change', dateStr);
    }
  }
}
</script>

<style scoped>

</style>